package com.group.eams.controller;






import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.MaintenPersonnelQueryDto;
import com.group.eams.pojo.entity.MaintenPersonnel;
import com.group.eams.pojo.vo.MaintenPersonnelListVo;
import com.group.eams.service.MaintenPersonnelService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 维保人员(MaintenPersonnel)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/maintenPersonnel")
public class MaintenPersonnelController  {
    /**
     * 服务对象
     */
    @Autowired
    private MaintenPersonnelService maintenPersonnelService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result list(MaintenPersonnelQueryDto mPersonnelQueryDto){
        Page<MaintenPersonnelListVo> page = maintenPersonnelService.findByQueryDto(mPersonnelQueryDto);
        return Result.buildSuccess(page.getTotal(), page.getRecords());

    }

    @RequestMapping(value = "/findById",method = RequestMethod.GET)
    public Result findById(@RequestParam Long id) {
        MaintenPersonnel maintenPersonnel = maintenPersonnelService.getById(id);
        return Result.buildSuccess(maintenPersonnel);
    }

    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result findAll() {
        LambdaQueryWrapper<MaintenPersonnel> queryWrapper = new LambdaQueryWrapper<>();

        return Result.buildSuccess(maintenPersonnelService.list(queryWrapper));
    }

    @RequestMapping(value = "/findPersonByVendorId", method = RequestMethod.GET)
    public Result findPersonByVendorId(@RequestParam Long maintenVendorId) {
        List<MaintenPersonnel> maintenPersonnelList = maintenPersonnelService.findPersonByVendorId(maintenVendorId);
        return Result.buildSuccess(maintenPersonnelList);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result add(@RequestBody MaintenPersonnel maintenPersonnel) {
        boolean result = maintenPersonnelService.save(maintenPersonnel);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result update(@RequestBody MaintenPersonnel maintenPersonnel) {
        LambdaUpdateWrapper<MaintenPersonnel> queryWrapper = new LambdaUpdateWrapper<>();
        queryWrapper.eq(MaintenPersonnel::getId, maintenPersonnel.getId());
        boolean result = maintenPersonnelService.update(maintenPersonnel, queryWrapper);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);

    }

    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public Result delete(@RequestParam Long id){
        LambdaQueryWrapper<MaintenPersonnel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MaintenPersonnel::getId, id);
        boolean result = maintenPersonnelService.remove(queryWrapper);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    public Result batchRemove(@RequestBody BatchDeleteDto batchDeleteDto){
        LambdaQueryWrapper<MaintenPersonnel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(MaintenPersonnel::getId, batchDeleteDto.getIds());
        boolean result = maintenPersonnelService.remove(queryWrapper);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }


}

